require 'net/pop' 
require 'rubygems' 
# gem i tmail
require 'tmail'
#@user = gets
#@passwd = gets
#puts "user is " + @user
#puts "password is" + @passwd
log_path = 'log.txt'
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
Net::POP3.start('pop.gmail.com', 995, 'kembo2008', 'liuliang') do |pop|
#Net::POP3.start('pop.gmail.com', 995, @user, @passwd) do |pop|
  if pop.mails.empty?
    puts 'No Mail.'
  else
    f = File.open(log_path,"a")
    pop.each_mail do |mail|
      email = TMail::Mail.parse(mail.pop)
      if email.subject == "Delivery Status Notification (Failure)"
        f.puts email.subject
        f.puts email["x-failed-recipients"].body
        f.puts "---------------------------------------"
      end
    end
    f.close
    puts "over"
  end
end

